package com.itheima.model.book.dtos;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * 图书事件DTO
 * 用于Kafka消息传递
 * 
 * @author itheima
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class BookEventDto implements Serializable {
    
    private static final long serialVersionUID = 1L;
    
    /**
     * 事件类型
     */
    private EventType eventType;
    
    /**
     * 图书ID
     */
    private Integer bookId;
    
    /**
     * 图书标题（可选，用于日志）
     */
    private String bookTitle;
    
    /**
     * 事件时间戳
     */
    private Long timestamp;
    
    /**
     * 事件类型枚举
     */
    public enum EventType {
        /**
         * 新增图书
         */
        BOOK_CREATED,
        
        /**
         * 更新图书
         */
        BOOK_UPDATED,
        
        /**
         * 删除图书
         */
        BOOK_DELETED,
        
        /**
         * 批量删除图书
         */
        BOOKS_BATCH_DELETED
    }
    
    /**
     * 创建删除事件
     */
    public static BookEventDto createDeleteEvent(Integer bookId, String bookTitle) {
        return new BookEventDto(
            EventType.BOOK_DELETED,
            bookId,
            bookTitle,
            System.currentTimeMillis()
        );
    }
    
    /**
     * 创建新增事件
     */
    public static BookEventDto createAddEvent(Integer bookId, String bookTitle) {
        return new BookEventDto(
            EventType.BOOK_CREATED,
            bookId,
            bookTitle,
            System.currentTimeMillis()
        );
    }
    
    /**
     * 创建更新事件
     */
    public static BookEventDto createUpdateEvent(Integer bookId, String bookTitle) {
        return new BookEventDto(
            EventType.BOOK_UPDATED,
            bookId,
            bookTitle,
            System.currentTimeMillis()
        );
    }
}

